package pri.ydy.educms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import pri.ydy.commonUtils.R;
import pri.ydy.educms.entity.CrmBanner;
import pri.ydy.educms.service.CrmBannerService;

/**
 * <p>
 * 首页banner表 管理员控制器
 * </p>
 *
 * @author testjava
 * @since 2020-12-12
 */
@RestController
@RequestMapping("/educms/banneradmin")
public class BannerAdminController {

    //TODO 这部分的后台前端页面未完成

    @Autowired
    private CrmBannerService bannerService;

    //分页查询banner
    @GetMapping("pageBanner/{page}/{limit}")
    public R pageBanner(@PathVariable long page,@PathVariable long limit){
        Page<CrmBanner> pageBanner =new Page<>(page,limit);
        bannerService.page(pageBanner,null);
        return  R.ok().data("items",pageBanner.getRecords()).data("total",pageBanner.getTotal());
    }

    //添加banner
    @PostMapping("addBanner")
    public R addBanner(@RequestBody CrmBanner banner){
        bannerService.save(banner);
        return R.ok();
    }

    //删除banner
    @DeleteMapping("remove/{id}")
    public R removeById(@PathVariable String  id){
        bannerService.removeById(id);
        return R.ok();
    }

    //修改banner
    @PostMapping("updateBanner")
    public R updateBanner(@RequestBody CrmBanner banner){
        bannerService.updateById(banner);
        return R.ok();
    }

    //查询banner
    @GetMapping("get/{id}")
    public R getBanner(@PathVariable String id){
        CrmBanner banner = bannerService.getById(id);
        return R.ok().data("item",banner);

    }

}

